package com.sgb.packers.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.android.exoplayer2.util.ParsableNalUnitBitArray;
import com.sgb.net.entity.ListResponse;
import com.sgb.packers.api.PackersNet;
import com.sgb.packers.entity.ProjectEntity;
import com.sgb.packers.entity.WorkStatisticsEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.util.SharedPreferenceUtil;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

/**
 * @author 王彬臣
 * @date 2021/11/25
 * @Description
 */
public class StatisticsViewModel extends BaseViewModel {
    public int pageNum = 1;
    public MutableLiveData<ListResponse<List<WorkStatisticsEntity>>> workStatisticsEntity = new MutableLiveData<>();

    public StatisticsViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /**
     * 发短信
     */
    public void getWorkStatistics(Map<String, Object> map, boolean isLoadMore) {
        mLoading.postValue(SHOW_LODING);
        pageNum = isLoadMore ? pageNum + 1 : 1;
        map.put("page", pageNum);
        map.put("limit", 20);
        PackersNet.getInstance().getService().getWorkStatistics(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<WorkStatisticsEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<WorkStatisticsEntity>>> data) {
                if (data != null && data.getData() != null) {
                    workStatisticsEntity.postValue(data.getData());
                }
            }
        });
    }
}
